from django.contrib import admin
from .models import OilInfo, GasStationInfo, ExpiryDatePrice, GroupChatQr, ApiChannel, RechargeRecord, \
    ChannelRiseInPrice, ChannelMenus, ReceiptTicket, OrderTicket, ChannelPrice, BankServerFee


class BankServerFeeAdmin(admin.ModelAdmin):
    list_display = ("pay_type_desc", "fix_time", "rate",)

    def pay_type_desc(self, model):
        return model.get_pay_type_display()

    pay_type_desc.short_description = "支付方式"


class ChannelPriceAdmin(admin.ModelAdmin):
    list_display = ("channel_name", "channel_key", "start_m", "end_m", "server_fee")

    def channel_name(self, model):
        return model.channel.name

    def channel_key(self, model):
        return model.channel.app_key

    channel_name.short_description = "渠道名称"
    channel_key.short_description = "渠道KEY"


class ChannelRiseInPriceAdmin(admin.ModelAdmin):
    list_display = ("channel_name", "czb_key")

    def channel_name(self, model):
        return model.channel.name


class OrderTicketAdmin(admin.ModelAdmin):
    list_display = ("buyerName", "order_id")
    search_fields = ("buyerName", "order_id")


class ReceiptTicketAdmin(admin.ModelAdmin):
    list_display = ("buyerName",)
    search_fields = ("buyerName",)


class RechargeRecordAdmin(admin.ModelAdmin):
    list_display = ("channel_name", "value", "create_time")

    def channel_name(self, model):
        return model.channel.name


class GroupChatQrAdmin(admin.ModelAdmin):
    list_display = ("expire_time",)


class ExpiryDatePriceAdmin(admin.ModelAdmin):
    list_display = ("month", "price")


class OilInfoInline(admin.TabularInline):
    model = OilInfo
    max_num = 30
    extra = 1  # 用于添加外键关系模型的空行
    verbose_name = '油枪信息'  # 外键关系模型列表最下面的添加另外一个***,所用的名字
    show_change_link = True  # 显示修改连接,这个很有用啊!!!!
    can_delete = True  # 是否显示删除框


class GasStationInfoAdmin(admin.ModelAdmin):
    list_display = ("gasName", "gasId", "provinceName", "cityName", "countyName")
    search_fields = ("gasId", "gasName", "provinceName", "cityName", "countyName")
    inlines = [OilInfoInline, ]


class ApiChannelAdmin(admin.ModelAdmin):
    list_display = ("id", "name",)


class ChannelMenusAdmin(admin.ModelAdmin):
    list_display = ("name",)


admin.site.register(ChannelMenus, ChannelMenusAdmin)
admin.site.register(BankServerFee, BankServerFeeAdmin)
admin.site.register(GasStationInfo, GasStationInfoAdmin)
admin.site.register(ExpiryDatePrice, ExpiryDatePriceAdmin)
admin.site.register(GroupChatQr, GroupChatQrAdmin)
admin.site.register(ApiChannel, ApiChannelAdmin)
admin.site.register(RechargeRecord, RechargeRecordAdmin)
admin.site.register(ChannelRiseInPrice, ChannelRiseInPriceAdmin)
admin.site.register(ReceiptTicket, ReceiptTicketAdmin)
admin.site.register(OrderTicket, OrderTicketAdmin)
admin.site.register(ChannelPrice, ChannelPriceAdmin)
